package com.godyao.mall.sms.controller;

import com.godyao.mall.core.model.ResultMsg;
import com.godyao.mall.core.utils.PageUtils;
import com.godyao.mall.sms.entity.HomeSubjectEntity;
import com.godyao.mall.sms.service.HomeSubjectService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 首页专题表【jd首页下面很多专题，每个专题链接新的页面，展示专题商品信息】
 *
 * @author godyao
 * @email godyao0801@qq.com
 * @date 2022-04-19 15:22:30
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("sms/homesubject")
public class HomeSubjectController {

    private final HomeSubjectService homeSubjectService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public ResultMsg list(@RequestParam Map<String, Object> params){
        PageUtils page = homeSubjectService.queryPage(params);

        return ResultMsg.resultSuccess(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public ResultMsg info(@PathVariable("id") Long id){
		HomeSubjectEntity homeSubject = homeSubjectService.getById(id);

        return ResultMsg.resultSuccess(homeSubject);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public ResultMsg save(@RequestBody HomeSubjectEntity homeSubject){
		homeSubjectService.save(homeSubject);

        return ResultMsg.resultSuccess("OK");
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public ResultMsg update(@RequestBody HomeSubjectEntity homeSubject){
		homeSubjectService.updateById(homeSubject);

        return ResultMsg.resultSuccess("OK");
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public ResultMsg delete(@RequestBody Long[] ids){
		homeSubjectService.removeByIds(Arrays.asList(ids));

        return ResultMsg.resultSuccess("OK");
    }

}
